#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''host instance factory'''

import sys
from .modules import *

hosts = {}

def getHost(hostname, user='', pwd=''):
    _hostname = hostname.lower()
    #get existed instance
    host = None
    if hosts.get(_hostname, None) is not None:
        return hosts[_hostname]
    #generate host instance
    try:
        host = eval('%s.%s(user,pwd)' % (_hostname, _hostname))
    except NameError:
        print(('Unsupported Host:', _hostname))
        return None
    hosts[_hostname] = host
    return host
        
if __name__ == '__main__':
    #test
    hostInstance = getHost('hoile')
    hostInstance = getHost('hotfile')
    if hostInstance is not None:
        hostInstance.login()
    hostInstance = getHost('hotfile','airnessub','19841012')
    if hostInstance is not None:
        hostInstance.login()
    